<!DOCTYPE html>

<html>

<head>
    <meta charset="utf-8">
    <title>添加非学员</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
</head>

<body>

    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-header">添加学员</div>
            <div class="layui-card-body" style="padding: 15px;">
                <form class="layui-form" action="" lay-filter="component-form-group" id="component-form-group">
                    <div class="layui-form-item">
                        <label class="layui-form-label">名字</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" lay-verify="name" autocomplete="off" placeholder="请输入名字" class="layui-input">
                        </div>
                    </div>


                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">验证手机</label>
                            <div class="layui-input-inline">
                                <input type="tel" name="phone" lay-verify="required|phone" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                    </div>

                    <div class="layui-form-item">

                        <div class="layui-inline">
                            <label class="layui-form-label">生日</label>
                            <div class="layui-input-inline">
                                <input type="text" name="date" id="LAY-component-form-group-date" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                    </div>


                    <div class="layui-form-item">
                        <label class="layui-form-label">便签选择</label>
                        <div class="layui-input-block">
                            <select name="studentType" lay-filter="aihao" id="studentType">
                             
                          </select>
                        </div>
                    </div>


                    <div class="layui-form-item">
                        <label class="layui-form-label">性别</label>
                        <div class="layui-input-block">
                            <input type="radio" name="sex" value="男" title="男" checked="">
                            <input type="radio" name="sex" value="女" title="女">

                        </div>
                    </div>

                    <div class="layui-form-item layui-layout-admin">
                        <div class="layui-input-block">
                            <div class="layui-footer" style="left: 0;">
                                <button class="layui-btn" lay-submit="" lay-filter="component-form-demo1">立即添加</button>
                                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>


    <script src="../../../layuiadmin/layui/layui.js"></script>
    <script src="../../../layuiadmin/url.js"></script>
    <script>
        layui.config({
            base: '../../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'form', 'laydate'], function() {
            var $ = layui.$,
                admin = layui.admin,
                element = layui.element,
                layer = layui.layer,
                laydate = layui.laydate,
                form = layui.form;

            $(function() {

                $.ajax({
                    url: applicationUrl + 'no-studentType/api/list',
                    type: "POST",
                    dataType: "json",
                    success: function(data) {
                        for (var i = 0; i < data.length; i++) {
                            $("#studentType").append("<option value='" + data[i].studentType + "'>" + data[i].names + "</option>");
                        }
                        form.render(); //注意渲染页面表单，否则不显示数据
                    }
                });

            });
            form.render(null, 'component-form-group');

            laydate.render({
                elem: '#LAY-component-form-group-date'
            });

            /* 自定义验证规则 */
            form.verify({
                name: function(value) {
                    if (value.length < 2) {
                        return '标题至少得2个字符啊';
                    }
                },
                pass: [/(.+){6,12}$/, '密码必须6到12位'],
                content: function(value) {
                    layedit.sync(editIndex);
                }
            });

            /* 监听指定开关 */
            form.on('switch(component-form-switchTest)', function(data) {
                layer.msg('开关checked：' + (this.checked ? 'true' : 'false'), {
                    offset: '6px'
                });
                layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
            });

            /* 监听提交 */
            form.on('submit(component-form-demo1)', function(data) {
                var name = data.field.name;
                var sex = data.field.sex;
                var studentType = data.field.studentType;
                var date = data.field.date;
                var phone = data.field.phone;
                console.log(data.field);
                $.ajax({
                    type: 'POST',
                    dataType: 'json',
                    data: {
                        name: name,
                        sex: sex,
                        phone: phone,
                        date: date,
                        studentType: studentType
                    },
                    url: applicationUrl + 'no-student/api/inser',
                    success: function(data) {
                        //  parent.layer.alert(JSON.stringify(data.msg));
                        layer.msg(data.msg);
                        $("#component-form-group")[0].reset();
                        layui.form.render();
                    },
                    error: function(data) {
                        layer.msg(data.msg);
                        layui.form.render();
                    }
                })

                return false;
            });
        });
    </script>
</body>

</html>